<template>
  <div class="mainApp">
    <router-view class="router-view"></router-view>
  </div>
</template>

<script>
import { getPlatInfo } from '@/api/common'
import platConfig from '@/utils/platConfig'

export default {
  name: 'App',
  created() {
    if (ZHXF_IS_AIO) {
      this.getPlatInfo()
    } else {
      this.setIcon()
    }
  },
  methods: {
    getPlatInfo() {
      getPlatInfo({
        filePath: platConfig.filePath,
        confName: platConfig.confName,
      })
        .then((res) => {
          this.setPlatInfo(res.data)
        })
        .catch(() => {
          this.setPlatInfo({})
        })
    },
    setPlatInfo(val) {
      let data = Object.assign({}, platConfig, val || {})
      document.title = data.simpleName
      const link = document.querySelector("link[rel*='icon']")
      link.type = 'image/x-icon'
      link.rel = 'shortcut icon'
      link.href = data.icoPath + '?' + new Date().getTime()
      this.$store.commit('setPlatConfigInfo', data)
    },
    setIcon() {
      // 根据分平台标识动态获取ico
      const that = this
      const link =
        document.querySelector("link[rel*='icon']") ||
        document.createElement('link')
      link.type = 'image/x-icon'
      link.rel = 'shortcut icon'
      link.href =
        REMOTESTATICPATH +
        that.GLOBAL.getPlatFormCodeByUrl() +
        '/favicon/favicon.ico'
      const $icon = document.getElementsByTagName('head')[0].appendChild(link)
      const _img = new Image()
      _img.src = link.href
      _img.onerror = function () {
        $icon.href = REMOTESTATICPATH + PLATCOEDEFAULT + '/favicon/favicon.ico'
      }
      if (typeof metaTitle !== 'undefined') {
        document.title = metaTitle
      }
    },
  },
}
</script>

<style lang="scss">
body {
  margin: 0px;
  padding: 0px;
  font-family: 'PingFang SC', 'Microsoft YaHei';
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.mainApp {
  position: absolute;
  height: 100%;
  width: 100%;
}
</style>
